package Week4.J0507;

import java.util.Scanner;

public class 连续子数组最大和_ACM版本_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n+1];
        int[] dp = new int[n+1];
        int ret = -200;

        for (int i = 1; i <= n; i++) {
            arr[i] = scanner.nextInt();
            dp[i] = Math.max(dp[i-1], 0) + arr[i];
            ret = Math.max(ret, dp[i]);
        }

        System.out.println(ret);
    }
}
